//
//  MainTabBarController.swift
//  微博
//
//  Created by 吴思达 on 16/3/5.
//  Copyright © 2016年 吴思达. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {
    
    @objc private func plusBtnDidClick() {
        print(__FUNCTION__)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let mainTabBar = MainTabBar()
        mainTabBar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)
        print(tabBar.classForCoder)
        setValue(mainTabBar, forKey: "tabBar")
        addChildViewControllers()
        print(tabBar.classForCoder)
        
        
        
        
        
    }
    
    private func addChildViewControllers() {
        
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(PorfileTableViewController(), title: "我的", imageName: "tabbar_profile")
    }
    
    private func addChildViewController(vc: UIViewController ,title: String,imageName: String) {
        vc.title = title
        vc.tabBarItem.title = title
//        tabBar.tintColor = UIColor.orangeColor()
        
        vc.tabBarItem.image = UIImage(named: imageName)
//                vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        
        
        //        addChildViewController(vc)
        
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        let nav = UINavigationController(rootViewController: vc)
        addChildViewController(nav)
    }
    
    
    /*
    // MARK: - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    }
    */
    
}
